package com.tjetc.rabbitmq;

import com.tjetc.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * 生产者 一般都在业务层发送
 *
 * @author gaoyongxiang
 * @version v1.0
 * @since 2025-11-04
 */
//@Component
@Service
public class Sender {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    private static final String SEND_MESSAGE = "msg";

    // 工作队列
    public void sendMsg() {
        rabbitTemplate.convertAndSend(RabbitMQConfig.BASIC_QUEUE, SEND_MESSAGE);
    }

    private static final String FANOUT_MESSAGE = "fanout_msg";

    // fanout
    public void sendFanout() {
        rabbitTemplate.convertAndSend(RabbitMQConfig.FANOUT_EXCHANGE, "", FANOUT_MESSAGE);
    }

    private static final String DIRECT_MESSAGE = "direct_msg";
    private static final String DIRECT_MESSAGE1 = "direct_msg1";

    // direct
    public void sendDirect1() {
        rabbitTemplate.convertAndSend(RabbitMQConfig.DIRECT_EXCHANGE, RabbitMQConfig.ROUTING_KEY1, DIRECT_MESSAGE);
    }

    public void sendDirect2() {
        rabbitTemplate.convertAndSend(RabbitMQConfig.DIRECT_EXCHANGE, RabbitMQConfig.ROUTING_KEY2, DIRECT_MESSAGE1);
    }

    // topic
    private static final String TOPIC_MESSAGE1 = "topic_msg1";
    private static final String TOPIC_MESSAGE2 = "topic_msg2";

    public void sendTopic1() {
        rabbitTemplate.convertAndSend(RabbitMQConfig.TOPIC_EXCHANGE, "lazy.orange.rabbit", TOPIC_MESSAGE1);
    }

    public void sendTopic2() {
        rabbitTemplate.convertAndSend(RabbitMQConfig.TOPIC_EXCHANGE, "lazy.orange.new.rabbit", TOPIC_MESSAGE2);
    }


}
